﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Truextend.Common.Data;

namespace Truextend.CoffeShop.Model.Tests
{
    [TestClass]
    public class ProductRepositoryTest
    {
        [TestMethod]
        public void SaveProductTest()
        {
            var uow = new EFUnitOfWork<CoffeShopEntities>();
            uow.Start();

            var productRepository = new Repository<Product>(uow);
            var restaurantRepository = new Repository<Restaurant>(uow);

            var product = new Product
                              {
                                      Name = "Hamburguesa Doble",
                                      Price = 15.5,
                                      Restaurant = restaurantRepository.DoQuery().First()
                                  };
            int oldCount = productRepository.GetCount();
            productRepository.Add(product);
            int currentCount = productRepository.GetCount();
            uow.End();
            int postCommitCount = productRepository.GetCount();

            Assert.AreEqual(oldCount, currentCount);
            Assert.AreEqual(oldCount + 1, postCommitCount);
        }

        public void ManagerExecutor(Action<IUnitOfWork> coreMethod)
        {
            var uow = new EFUnitOfWork<CoffeShopEntities>();
            uow.Start();
            coreMethod(uow);
            uow.End();
        }
    }

    
}
